package com.itheima.health.jobs;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author ：youhaoxuan
 * @date ：Created in 2020/1/2
 * @description ：
 * @version: 1.0
 */

@Slf4j
public class ClearlOrderSetting {

    @Reference
    private OrderSettingService orderSettingService;

    public void clearOrder(){
        log.info("清理垃圾预约开始");


        try {
            Calendar cale = Calendar.getInstance();
            SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd");
            //增加一个月
            cale.add(Calendar.MONTH, 1);
            cale.set(Calendar.DAY_OF_MONTH, 0);
            String lastday = formatTemp.format(cale.getTime());
            Date lastDate =formatTemp.parse(lastday);

            orderSettingService.deleteByOrderDateBefore(lastDate);

        } catch (Exception e) {
            e.printStackTrace();
            log.error("",e);
        } finally {
            log.info("[清理垃圾预约]完成……");
        }


    }
}
